<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta charset="utf-8">
    <title>生产账号修改</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../layuiadmin/style/admin.css" media="all">
</head>
<body>
<div class="layui-form" lay-filter="layuiadmin-prisoner-form-list" id="layuiadmin-prisoner-form-list"
     style="padding: 20px 30px 0 0;">
    <input type="hidden" name="id" id="id" value="${prisoner.prisoner.id}"/>
    <div class="layui-form-item">
        <label class="layui-form-label">编号</label>
        <div class="layui-input-inline">
            <input type="text" name="prisonercode"
                   lay-verify="required|prisonercode|number"
                   maxlength="10"
                   readonly

                   placeholder="请输入编号" autocomplete="off"
                   class="layui-input layui-disabled" value="${prisoner.prisoner.prisonercode}">
        </div>
        <label class="layui-form-label">姓名</label>
        <div class="layui-input-inline">
            <input type="text" name="prisonername"
                   maxlength="9"
                   lay-verify="required" placeholder="请输入姓名" autocomplete="off"
                   class="layui-input" value="${prisoner.prisoner.prisonername}">
        </div>

    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">登录密码</label>
        <div class="layui-input-inline">
            <input type="password" name="password"
                   lay-verify="required|password|number"
                   maxlength="6"
                   placeholder="请输入密码" autocomplete="off" class="layui-input" value="${prisoner.prisoner.password}">
        </div>
        <!--
      <label class="layui-form-label">罪名</label>
      <div class="layui-input-inline">
        <input type="crimename" name="crimename" lay-verify="required" placeholder="请输入罪名" autocomplete="off" class="layui-input" value="${prisoner.prisoner.crimename}">
      </div>
      
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">民族</label>
      <div class="layui-input-inline">
        <input type="nation" name="nation" lay-verify="required" placeholder="请输入民族" autocomplete="off" class="layui-input" value="${prisoner.prisoner.nation}">
      </div>
      <label class="layui-form-label">年龄</label>
      <div class="layui-input-inline">
        <input type="age" name="age" lay-verify="required|number" placeholder="请输入年龄" autocomplete="off" class="layui-input" value="${prisoner.prisoner.age}">
      </div>
        -->
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">头像图片:</label>
        <div class="layui-upload layui-input-block">
            <input type="hidden" id="headfilepath" name="headfilepath"
                   value="${prisoner.prisoner.headfilepath }"/>
            <button type="button"
                    class="layui-btn layui-btn-primary"
                    id="headfilepathBtn"><i class="layui-icon">&#xe67c;</i>选择文件
            </button>
            <span>注：图片像素尺寸不能超过128x160</span>
            <!-- 
            <button type="button" class="layui-btn layui-btn-warm" id="uploadBtn">开始上传</button>
             -->
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">指纹文件:</label>
        <div class="layui-upload layui-input-block">
            <input type="hidden" id="fingerfilepath" name="fingerfilepath"
                   value="${prisoner.prisoner.fingerfilepath }"/>
            <button type="button" class="layui-btn layui-btn-primary" id="fingerfilepathBtn"><i class="layui-icon">&#xe67c;</i>选择文件
            </button>
            <!-- 
            <button type="button" class="layui-btn layui-btn-warm" id="uploadBtn">开始上传</button>
             -->
        </div>
    </div>

    <div class="layui-form-item layui-hide">
        <input type="button" lay-submit lay-filter="layuiadmin-prisoner-form-submit"
               id="layuiadmin-prisoner-form-submit" value="确认添加">
        <input type="button" lay-submit lay-filter="layuiadmin-prisoner-form-edit" id="layuiadmin-prisoner-form-edit"
               value="确认编辑">
    </div>
</div>

<script src="../layuiadmin/layui/layui.js"></script>
<script src="../layuiadmin/js/common/jquery.js"></script>
<script>
    layui.config({
        base: '../layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form', 'laydate', 'upload'], function () {
        var $ = layui.$
            , admin = layui.admin
            , element = layui.element
            , layer = layui.layer
            , laydate = layui.laydate
            , upload = layui.upload
            , form = layui.form;

        upload.render({
            elem: '#headfilepathBtn'
            ,url: '../prisoner/saveHeadfilepath'
             ,accept:'images'
            ,acceptMime: 'image/jpg'
            ,exts: 'jpg|jpeg|JPG|JPEG'
            , auto: false
            , data: {
                id: function () {
                    return $('#id').val();
                }
            }
            , choose: function (obj) {
                var flag = true;
                obj.preview(function (index, file, result) {

                });

                if (flag) {
                    //确认框
                    layer.confirm('确定导入文件吗？', {icon: 3, title: '提示'}, function (index) {
                        layer.msg('正在提交请稍候。。。', {icon: 16, time: '-1', shade: [0.5, '#000', true]});
                        //读取本地文件
                        obj.preview(function (index, file, result) {
                            console.log(file);            //file表示文件信息，result表示文件src地址
                            var img = new Image();
                            img.src = result;
                            img.onload = function () { //初始化夹在完成后获取上传图片宽高，判断限制上传图片的大小。
                                if (img.width <= 128 && img.height <= 160) {
                                    obj.upload(index, file); //满足条件调用上传方法
                                } else {
                                    flag = false;
                                    layer.msg("您上传的头像尺寸最大不能超过128x160！");
                                    return false;
                                }
                            }
                            return flag;
                        });
                        layer.close(index);
                    });
                }
            }

            , done: function (res) {
                var code = res.code;
                if (code && code == 0) {
                    //上传完毕回调
                    layer.msg("文件已经成功上传！");
                } else {
                    var msg = res.msg;
                    layer.alert(msg);
                    return;
                }
            }
        });

        upload.render({
            elem: '#fingerfilepathBtn'
            , url: '../prisoner/saveFingerfilepath'
            , accept: 'file'
            , size: 3
            , exts: 'dat'
            , auto: false
            , data: {
                id: function () {
                    return $('#id').val();
                }
            }
            , choose: function (obj) {
                //确认框
                layer.confirm('确定导入文件吗？', {icon: 3, title: '提示'}, function (index) {
                    layer.msg('正在提交请稍候。。。', {icon: 16, time: '-1', shade: [0.5, '#000', true]});
                    //读取本地文件
                    obj.preview(function (index, file, result) {
                        //单个重传
                        obj.upload(index, file);
                    });
                    layer.close(index);
                });
            }

            , done: function (res) {
                var code = res.code;
                if (code && code == 0) {
                    //上传完毕回调
                    layer.msg("文件已经成功上传！");
                } else {
                    var msg = res.msg;
                    layer.alert(msg);
                    return;
                }
            }
        });

        //自定义验证规则
        form.verify({
            prisonercode: function (value) {
                if (value.length != 10) {
                    return '罪犯编号必须为10位';
                }
            }
            , password: [
                /^[\S]{6,6}$/
                , '密码必须6位，且不能出现空格'
            ]
            , content: function (value) {
                layedit.sync(editIndex);
            }
        });

        //监听提交
        form.on('submit(layuiadmin-prisoner-form-submit)', function (obj) {
            var field = obj.field; //获取提交的字段
            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引

            //提交 Ajax 成功后，关闭当前弹层并重载表格
            //$.ajax({});

            layer.confirm('确定操作?', function (index) {
                layer.msg('正在提交请稍候。。。', {icon: 16, time: '-1', shade: [0.5, '#000', true]});
                admin.req({
                    url: '../prisoner/update' //实际使用请改成服务端真实接口
                    , data: field
                    , type: 'POST'
                    , done: function (res) {
                        layer.msg(res.msg);
                    }
                });
            });

            //parent.layui.table.reload('LAY-prisoner-content-list'); //重载表格
            //parent.layer.close(index); //再执行关闭
        });

    })
</script>
</body>
</html>